import Vue from 'vue'
import Router from 'vue-router'

// front
import fIndex from '@/view/front/Index'
import bLogin from '@/view/back/Login'
import bParent from '@/view/back/Parent'
import bDashboard from '@/view/back/Dashboard'

Vue.use(Router)

let _router = new Router({
  routes: [
    {
      path: '/',
      name: 'fIndex',
      component: fIndex,
      meta: {
        title: '帮助',
        requireLogin: false
      }
    }, {
      path: '/login',
      name: 'login',
      component: bLogin,
      meta: {
        title: '登录',
        requireLogin: false
      }
    }, {
      path: '/app',
      name: 'app',
      component: bParent,
      meta: {
        title: '帮助',
        requireLogin: false
      },
      children: [{
        path: 'index',
        name: 'b_index',
        component: bDashboard}
      ]
    }
  ]
})

_router.beforeEach((to, from, next) => {
  if (to !== undefined) {
    if (to.meta.requireLogin) {
      next({
        path: '/login'
      })
    }
    if (to.path === '/app' || to.path === '/app/') {
      next({path: '/app/index'})
    } else {
      next()
    }
  }
})

export default _router
